#include "ThreadPool.hpp"
#include "Task.hpp"
#include <iostream>
#include <string>
#include <memory>
#include <ctime>

int main()
{
    // 获取单例的可能是多线程啊！！！
    // 程序已经加载
    EnableFile();
    LOG(DEBUG, "程序已经加载");
    sleep(3);
    ThreadPool<Task>::GetInstance();
    sleep(2);

    ThreadPool<Task>::GetInstance();
    sleep(2);

    ThreadPool<Task>::GetInstance();
    sleep(2);

    ThreadPool<Task>::GetInstance();
    sleep(2);


    

    srand(time(nullptr) ^ pthread_self() ^ getpid());
    //std::unique_ptr<ThreadPool<Task>> tp = std::make_unique<ThreadPool<Task>>(5);

    int tasknum = 10;
    while(tasknum)
    {
        int a = rand() % 10 + 1;
        usleep(1234);
        int b = rand() % 5 + 1;
        
        Task t(a,b);
        t.DebugToString();
        ThreadPool<Task>::GetInstance()->Enqueue(t);

        sleep(1);
        --tasknum;
    }
    
    ThreadPool<Task>::GetInstance()->Stop();
    ThreadPool<Task>::GetInstance()->Wait();
    return 0;
}

// int main()
// {
//     EnableFile();
//     //EnableScreen();
//     srand(time(nullptr) ^ pthread_self() ^ getpid());
//     std::unique_ptr<ThreadPool<Task>> tp = std::make_unique<ThreadPool<Task>>(5);
//     tp->InitThreadPool();
//     tp->Start();
//     int tasknum = 10;
//     while(tasknum)
//     {
//         int a = rand() % 10 + 1;
//         usleep(1234);
//         int b = rand() % 5 + 1;
        
//         Task t(a,b);
//         t.DebugToString();
//         tp->Enqueue(t);

//         sleep(1);
//         --tasknum;
//     }
    
//     tp->Stop();
//     tp->Wait();
// }

